package c.h.a.w.m;

import android.content.Context;
import android.graphics.drawable.Drawable;
import android.os.AsyncTask;
import android.os.Handler;
import android.os.Looper;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.CompoundButton.OnCheckedChangeListener;
import android.widget.ImageView;
import android.widget.ProgressBar;
import android.widget.TextView;
import android.widget.Toast;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import androidx.recyclerview.widget.RecyclerView.z;
import c.h.a.m0.j;
import c.h.a.w.e;
import c.h.a.w.k.e.f;
import com.liuzh.deviceinfo.DeviceInfoApp;
import com.liuzh.deviceinfo.analyzer.view.BaseFloatingDetailView;
import java.lang.ref.SoftReference;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

/* compiled from: RepeatFileFloatingView */
public class g extends BaseFloatingDetailView {
    public static final /* synthetic */ int k = 0;
    public List<c.h.a.w.k.e.b> e;
    public b f;
    public RecyclerView g;
    public ProgressBar h;
    public int i = 0;
    public final Handler j = new Handler(Looper.getMainLooper());

    /* compiled from: RepeatFileFloatingView */
    public class a implements f {

        /* compiled from: RepeatFileFloatingView */
        public class a implements Runnable {
            public void run() {
                g gVar = g.this;
                int i = g.k;
                gVar.d();
            }
        }

        public void a(Map<String, List<e>> map, List<c.h.a.w.k.e.b> list) {
            g.this.post(new a());
        }
    }

    /* compiled from: RepeatFileFloatingView */
    public class b extends RecyclerView.e<z> {
        public LayoutInflater c;

        public b(a aVar) {
        }

        public int a() {
            List list = g.this.e;
            return list != null ? list.size() : 0;
        }

        public int c(int i) {
            List list = g.this.e;
            return (list == null || i >= list.size()) ? 0 : ((c.h.a.w.k.e.b) g.this.e.get(i)).e;
        }

        public void f(z zVar, int i) {
            c.h.a.w.k.e.b bVar = (c.h.a.w.k.e.b) g.this.e.get(i);
            int i2 = 0;
            int i3 = 1;
            if (zVar instanceof c) {
                c cVar = (c) zVar;
                cVar.w.setOnCheckedChangeListener(null);
                cVar.w.setChecked(bVar.d());
                TextView textView = cVar.u;
                if (TextUtils.isEmpty(bVar.g)) {
                    bVar.g = j.f(bVar.c());
                }
                textView.setText(bVar.g);
                cVar.t.setText(g.this.getContext().getString(2131690027, new Object[]{Integer.valueOf(bVar.a())}));
                cVar.v.setRotation(bVar.c.a ? -90.0f : 90.0f);
                cVar.w.setOnCheckedChangeListener(cVar);
            } else if (zVar instanceof d) {
                e b = bVar.b();
                if (b != null) {
                    Drawable drawable;
                    d dVar = (d) zVar;
                    dVar.z.setOnCheckedChangeListener(null);
                    dVar.z.setChecked(bVar.d());
                    dVar.t.setText(b.e);
                    dVar.u.setText(b.b());
                    TextView textView2 = dVar.x;
                    int i4 = bVar.e;
                    if (i4 >= 0 && i4 < bVar.a.size()) {
                        String toLowerCase = ((e) bVar.a.get(bVar.e)).b().toLowerCase();
                        for (String startsWith : c.h.a.w.k.e.b.o) {
                            if (toLowerCase.startsWith(startsWith)) {
                                break;
                            }
                        }
                    }
                    i3 = 0;
                    if (i3 == 0) {
                        i2 = 8;
                    }
                    textView2.setVisibility(i2);
                    dVar.v.setText(j.b.format(Long.valueOf(b.b)));
                    dVar.w.setText(j.f(b.a));
                    dVar.z.setOnCheckedChangeListener(dVar);
                    ImageView imageView = dVar.y;
                    SoftReference softReference = bVar.i;
                    if (softReference == null || softReference.get() == null) {
                        drawable = DeviceInfoApp.c.getDrawable(2131231010);
                    } else {
                        drawable = (Drawable) bVar.i.get();
                    }
                    imageView.setImageDrawable(drawable);
                }
            }
        }

        public z g(ViewGroup viewGroup, int i) {
            if (this.c == null) {
                this.c = LayoutInflater.from(viewGroup.getContext());
            }
            if (i == -1) {
                return new c(this.c.inflate(2131492989, viewGroup, false));
            }
            return new d(this.c.inflate(2131492988, viewGroup, false));
        }
    }

    /* compiled from: RepeatFileFloatingView */
    public class c extends z implements OnCheckedChangeListener {
        public TextView t;
        public TextView u;
        public ImageView v;
        public CheckBox w;

        /* compiled from: RepeatFileFloatingView */
        public class a implements OnClickListener {

            /* compiled from: RepeatFileFloatingView */
            public class a implements Runnable {
                public final /* synthetic */ int a;
                public final /* synthetic */ c.h.a.w.k.e.b b;

                public a(int i, c.h.a.w.k.e.b bVar) {
                    this.a = i;
                    this.b = bVar;
                }

                public void run() {
                    List list = g.this.e;
                    int i = this.a + 1;
                    c.h.a.w.k.e.b bVar = this.b;
                    if (bVar.h == null) {
                        bVar.h = new ArrayList(bVar.a());
                    }
                    if (bVar.h.size() != bVar.a()) {
                        bVar.h.clear();
                        for (int i2 = 0; i2 < bVar.a(); i2++) {
                            c.h.a.w.k.e.b bVar2 = new c.h.a.w.k.e.b(i2, bVar.a, bVar.b, bVar.c, bVar.d);
                            bVar2.i = bVar.i;
                            bVar.h.add(bVar2);
                        }
                    }
                    list.addAll(i, bVar.h);
                    b bVar3 = g.this.f;
                    bVar3.a.e(this.a + 1, this.b.a());
                }
            }

            /* compiled from: RepeatFileFloatingView */
            public class b implements Runnable {
                public final /* synthetic */ c.h.a.w.k.e.b a;
                public final /* synthetic */ int b;

                public b(c.h.a.w.k.e.b bVar, int i) {
                    this.a = bVar;
                    this.b = i;
                }

                public void run() {
                    for (int a = this.a.a(); a > 0; a--) {
                        g.this.e.remove(this.b + a);
                    }
                    b bVar = g.this.f;
                    bVar.a.f(this.b + 1, this.a.a());
                }
            }

            public a(g gVar) {
            }

            public void onClick(View view) {
                int e = c.this.e();
                if (e >= 0 && e < g.this.e.size()) {
                    c.h.a.w.k.e.b bVar = (c.h.a.w.k.e.b) g.this.e.get(e);
                    c.h.a.w.k.e.c cVar = bVar.c;
                    cVar.a ^= 1;
                    g.this.f.d(e);
                    if (bVar.c.a) {
                        if (e == g.this.e.size() - 1 || ((c.h.a.w.k.e.b) g.this.e.get(e + 1)).e == -1) {
                            g.this.g.post(new a(e, bVar));
                        }
                    } else if (e != g.this.e.size() - 1 && ((c.h.a.w.k.e.b) g.this.e.get(e + 1)).e != -1) {
                        g.this.g.post(new b(bVar, e));
                    }
                }
            }
        }

        public c(View view) {
            super(view);
            this.t = (TextView) view.findViewById(2131296594);
            this.u = (TextView) view.findViewById(2131296904);
            this.v = (ImageView) view.findViewById(2131296545);
            this.w = (CheckBox) view.findViewById(2131296443);
            view.setOnClickListener(new a(g.this));
        }

        public void onCheckedChanged(CompoundButton compoundButton, boolean z) {
            g gVar = g.this;
            gVar.g.post(new h(gVar, e(), z));
        }
    }

    /* compiled from: RepeatFileFloatingView */
    public class d extends z implements OnCheckedChangeListener {
        public TextView t;
        public TextView u;
        public TextView v;
        public TextView w;
        public TextView x;
        public ImageView y;
        public CheckBox z;

        public d(View view) {
            super(view);
            this.t = (TextView) view.findViewById(2131296753);
            this.u = (TextView) view.findViewById(2131296786);
            this.v = (TextView) view.findViewById(2131297052);
            this.w = (TextView) view.findViewById(2131296904);
            this.y = (ImageView) view.findViewById(2131296628);
            this.x = (TextView) view.findViewById(2131297337);
            this.z = (CheckBox) view.findViewById(2131296443);
        }

        public void onCheckedChanged(CompoundButton compoundButton, boolean z) {
            g gVar = g.this;
            gVar.g.post(new h(gVar, e(), z));
        }
    }

    public g(Context context) {
        super(context);
    }

    public void a() {
        if (this.a.e.a(new a()) != null) {
            d();
        }
    }

    public void b() {
        this.g = (RecyclerView) findViewById(2131296830);
        this.h = (ProgressBar) findViewById(2131296806);
        this.g.setLayoutManager(new LinearLayoutManager(getContext()));
        b bVar = new b(null);
        this.f = bVar;
        this.g.setAdapter(bVar);
        findViewById(2131296880).setOnClickListener(this);
        findViewById(2131296452).setOnClickListener(this);
    }

    public final void d() {
        this.e = this.a.e.c;
        this.f.a.b();
        c();
        findViewById(2131296701).setVisibility(0);
        this.h.setVisibility(8);
    }

    public int getLayoutId() {
        return 2131492961;
    }

    public void onClick(View view) {
        super.onClick(view);
        int id = view.getId();
        boolean z = false;
        if (id != 2131296452) {
            if (id == 2131296880) {
                List list = this.e;
                if (list != null) {
                    Iterator it = list.iterator();
                    while (true) {
                        boolean z2 = true;
                        if (!it.hasNext()) {
                            break;
                        }
                        c.h.a.w.k.e.b bVar = (c.h.a.w.k.e.b) it.next();
                        if (this.i != 0) {
                            z2 = false;
                        }
                        bVar.h(z2);
                    }
                    this.i = this.i == 0 ? this.e.size() : 0;
                    view = findViewById(2131296452);
                    if (this.i != 0) {
                        z = true;
                    }
                    view.setEnabled(z);
                    this.f.a.b();
                }
            }
        } else if (this.i < 0) {
            this.i = 0;
            Toast.makeText(getContext(), 2131689838, 0).show();
        } else {
            c.h.a.v.a.b.c("duplicate_clean", null);
            view = LayoutInflater.from(getContext()).inflate(2131492941, null);
            TextView textView = (TextView) view.findViewById(2131296810);
            ProgressBar progressBar = (ProgressBar) view.findViewById(2131296807);
            progressBar.setMax(this.i);
            b.b.c.f.a aVar = new b.b.c.f.a(getContext());
            String string = DeviceInfoApp.c.getString(2131690407);
            androidx.appcompat.app.AlertController.b bVar2 = aVar.a;
            bVar2.d = string;
            bVar2.t = view;
            bVar2.s = 0;
            bVar2.m = false;
            AsyncTask.execute(new j(this, textView, progressBar, aVar.g()));
        }
    }
}
